package july.android.cakes.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import july.android.cakes.service.SService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author S_Cake
 * @version 个人中心（学生和老师）
 */

@RestController
@EnableAutoConfiguration
public class CController {
    @Autowired
    private SService sv;
    
    
    //修改学生头像
    @RequestMapping("/UP_studentIcon")
    public void do_UPStuIcon(@RequestParam("stu_id") String id,@RequestParam("icon")String icon, @RequestParam("random")String random,HttpServletResponse hp)throws Exception{
         sv.UPStuIcon(id,icon,random);
        // hp.sendRedirect("http://123.206.198.158/back.html");
         //hp.sendRedirect("http://127.0.0.1/back.html");
    }
    
     //修改教师头像
    @RequestMapping("/UP_teacherIcon")
    public void do_UPTeaIcon(@RequestParam("tea_id") String id,@RequestParam("icon")String icon, @RequestParam("random")String random,HttpServletResponse hp)throws Exception{
         sv.UPTeaIcon(id,icon,random);
         //hp.sendRedirect("http://123.206.198.158/back.html");
        // hp.sendRedirect("http://127.0.0.1/back.html");
    }

     //修改社团头像
    @RequestMapping("/UP_teamIcon")
    public void do_UPTeamIcon(@RequestParam("team_id") String id,@RequestParam("icon")String icon, @RequestParam("random")String random,HttpServletResponse hp)throws Exception{
         sv.UPTeamIcon(id,icon,random);
        //hp.sendRedirect("http://123.206.198.158/back.html");
         //hp.sendRedirect("http://127.0.0.1/back.html");
    }
    
    //根据传入的学生账号判断是什么专业
    @RequestMapping("/get_major")
    public String do_getmajor(@RequestParam("id") String id){
        return sv.getmajor(id);
    }

     //修改昵称
    @RequestMapping("/modify_nickname")
    public void do_modifynickname(@RequestParam("id") String id,@RequestParam("nickname")String nickname){
        sv.modifynickname(id,nickname);
    }

   //根据传入的学生学号获得昵称，若没有昵称，默认为学生姓名
   //此方法在CMessage.java中已有，可通过 @RequestMapping("/get_nickname")调用


   //根据传入的学生账号以及头像的路径设置学生的新头像
    @RequestMapping("/add_stuimage")
    public void do_addstuimage(@RequestParam("id") String id,@RequestParam("icon")String icon)throws Exception{
         sv.addstuimage(id,icon);
    }

    //根据传入的学生账号获取昵称
    @RequestMapping("/get_nickName")
    public String do_getNickname(@RequestParam("id") String id)throws Exception{
        return sv.getNickname(id);
    }
    
     //根据传入的学生账号获取头像，返回路径
    @RequestMapping("/get_stuimage")
    public String do_getstuimage(@RequestParam("id") String id)throws Exception{
        return sv.getstuimage(id);
    }

    //根据传入的教师工号以及头像的路径设置教师的新头像
     @RequestMapping("/add_teacherimage")
    public void do_addteacherimage(@RequestParam("id")String id,@RequestParam("icon")String icon){
        sv.addteacherimage(id,icon);
    }

    //根据传入的教师工号获取头像，返回路径
    @RequestMapping("/get_teacherimage")
    public String do_getteacherimage(@RequestParam("id")String id)throws Exception{
        return sv.getteacherimage(id);
    }

    //根据传入的教师工号获取名字
    @RequestMapping("/get_teacherName")
    public String do_getteacherName(@RequestParam("id")String id)throws Exception{
        return sv.getteacherName(id);
    }
    
   //根据传入的社团账号获取社团的头像，返回路径 
    @RequestMapping("/get_depimage")
    public String do_getdepimage(@RequestParam("id") String id)throws Exception{
        return sv.getdepimage(id);
    }
    
    //根据传入的教师工号获取教师详细信息
    @RequestMapping("/get_teacherdetail")
    public List<Map<String,Object>>do_getteacherdetail(@RequestParam("id")String id){
        return sv.getteacherdetail(id);
    }

    //修改教师联系电话
    @RequestMapping("/change_teacherphone")
    public void do_changeteacherphone(@RequestParam("id")String id,@RequestParam("tel")String tel){
        sv.changeteacherphone(id,tel);
    }

    //修改教师邮箱地址
    @RequestMapping("/change_teacheremail")
    public void do_changeteacheremail(@RequestParam("tea_id")String tea_id,@RequestParam("tea_email")String tea_email){
        sv.changeteacheremail(tea_id,tea_email);
    }

    //修改教师办公室地址
    @RequestMapping("/change_teacheraddress")
    public void do_changeteacheraddress(@RequestParam("id")String id,@RequestParam("address")String address) {
        sv.changeteacheraddress(id,address);
    }

    //学生登录验证
    @RequestMapping("/student_enter")
    public String do_student_enter(@RequestParam("id") String id, @RequestParam("passw") String passw) {
        return sv.studentEnter(id,passw);
    }

    //教师登录验证
    @RequestMapping("/teacher_enter")
    public String do_teacher_enter(@RequestParam("id") String id, @RequestParam("passw") String passw) {
        return sv.teacherEnter(id,passw);
    }

    //社团登录验证
    @RequestMapping("/team_enter")
    public String do_team_enter(@RequestParam("id") String id, @RequestParam("passw") String passw) {
        return sv.teamEnter(id,passw);
    }

}
